#include "window.h"

#include <QOpenGLFunctions_4_3_Core>


namespace mesh
{


window::window(QScreen* screen)
  : QWindow(screen)
{
  // Tell Qt we will use OpenGL for this window
  setSurfaceType(OpenGLSurface);

  // Specify the format and create platform-specific surface
  QSurfaceFormat format;
  format.setDepthBufferSize(24);
  format.setMajorVersion(4);
  format.setMinorVersion(3);
  format.setSamples(4);
  format.setProfile(QSurfaceFormat::CoreProfile);
  setFormat(format);
  create();

  // Create an OpenGL context
  _context = std::unique_ptr<QOpenGLContext>(new QOpenGLContext);
  _context->setFormat(format);
  _context->create();

  // Make the context current on this window
  _context->makeCurrent(this);

  // Obtain a functions object and resolve all entry points
  // m_funcs is declared as: QOpenGLFunctions_4_3_Core* m_funcs
  _gl_function = _context->versionFunctions();
  if (!_gl_function)
  {
    qWarning("&quot;Could not obtain OpenGL versions object&quot;");
    exit(1);
  }
  _gl_function->initializeOpenGLFunctions();
}


} //mesh
